<template>
  <div>
    <div>
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="nubmer"
          label="人数">
        </el-table-column>
        <el-table-column
          prop="one"
          label="闲一">
        </el-table-column>
        <el-table-column
          prop="two"
          label="闲二">
        </el-table-column>
        <el-table-column
          prop="three"
          label="闲三">
        </el-table-column>
        <el-table-column
          prop="serviceCharge"
          label="手续">
        </el-table-column>
        <el-table-column
          prop="reversion"
          label="回收">
        </el-table-column>
        <el-table-column
          prop="recycle"
          label="回收率">
        </el-table-column>
        <el-table-column
          prop="recycleTimer"
          label="每场回收">
        </el-table-column>
      </el-table>
    </div>
    <div style="max-width: 500px">
      <el-form :inline="true" :model="formData" class="demo-form-inline" style="margin-top: 20px">
        <el-form-item>
          <el-checkbox-group v-model="checkboxGroup" size="medium">
            <el-checkbox-button v-for="p in pos" :label="p" :key="p">{{p}}</el-checkbox-button>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item >
          <el-button  style="margin-left: 70px" type="primary" icon="el-icon-video-play" @click="onSubmit">提交出牌控制</el-button>
        </el-form-item>
      </el-form>
    </div>
    <hr>
    <div style="max-width: 500px">
      <el-input style="width: 55%" v-model.number="recovery" type="number" placeholder="请输入内容"></el-input>
      <el-button type="primary" icon="el-icon-setting" @click="recycleClick">设 置 回 收 率</el-button>
    </div>
    <hr>
    <div style="max-width: 500px;margin-top: 20px">
      <el-button style="margin-left: 280px"  type="primary" icon="el-icon-video-play" @click="stopService">暂停/开启服务</el-button>
    </div>
  </div>
</template>

<script>
  const posOptions = ['闲一', '闲二', '闲三'];
  import axios from 'axios'

  export default {
    created() {
      axios.get("/ebghscene").then(resp => {
        if (resp.data.result) {
          this.tableData = [resp.data.msg]
        }
      })
    },
    data() {
      return {
        recovery: '',
        tableData: [],
        formData: {
          type: ''
        },
        checkboxGroup: [],
        pos: posOptions
      }
    },
    methods: {
      recycleClick() {
        if (this.recovery === "") {
          this.$notify.error({
            title: '错误',
            message: '请输入调整率'
          });
          return
        }
        console.log(this.recovery)
        axios.get("ebgsetrecovery", {
          params: {
            recovery: this.recovery
          }
        }).then(resp => {
          this.$notify({
            title: '成功',
            message: resp.data.msg,
            type: 'success'
          });
        }).catch(err => {
          this.$notify({
            title: '警告',
            message: err.data.error,
            type: 'warning'
          });
        })
      },
      stopService() {
        axios.get("ebghstopservice").then(resp => {
          if (resp.data.result) {
            alert(resp.data.msg)
          } else {
            alert(resp.data.error)
          }
        })
      },

      onSubmit() {
        let o = this.checkboxGroup.indexOf("闲一");
        let tw = this.checkboxGroup.indexOf("闲二");
        let th = this.checkboxGroup.indexOf("闲三");
        let type = 1;
        if (o !== 1 && tw !== 1 && th !== 1 ) {
          type = 1;
        } else if (o !== 1 && tw !== 1 && th !== -1) {
          type = 2;
        } else if (o !== 1 && tw !== -1 && th === -1) {
          type = 3;
        } else if (o !== 1 && tw !== -1 && th === 1) {
          type = 4;
        } else if (o !== -1 && tw === -1 && th === 1 ) {
          type = 5;
        } else if (o !== -1 && tw === -1 && th === -1) {
          type = 6;
        } else if (o !== -1 && tw === 1 && th !== -1 ) {
          type = 7;
        }else if (o !== -1 && tw === 1 && th !== 1 ) {
          type = 8;
        }
        if (type != -1) {
          axios.get("/ebghcontroller", {
            params: {
              type: type
            }
          }).then(resp => {
            if (resp.data.result) {
              this.checkboxGroup = [];
              alert(resp.data.msg)
            } else {
              alert(resp.data.error)
            }
          })
        }
        console.log(type);
      }
    }
  }
</script>

<style scoped>

</style>
